首页>题解>CF1113B Sasha and Magnetic Machines
Notice that the values of \(a_i\) are small, so we can consider a brute-force approach. We iterate \(i\) and \(j\) from \(\min\limits_{i=1}^{n} a_i\) to \(\max\limits_{i=1}^{n} a_i\). If we encounter \(i, j \in a\), we check whether \(i\) is divisible by some \(x\) (where \(x\) can be iterated over in a third loop). If so, we simply take the minimum between the current answer and the answer after the operation. The time complexity is \(\mathcal O\left(\left(\max\limits_{i=1}^{n}a_i-\min\limits_{i=1}^{n}a_i+1\right)^2\cdot\sqrt{\max\limits_{i=1}^{n}a_i}\right)\), and the total number of loop iterations is at most \(10^5\), so this solution is feasible for the problem.